/**
 * 
 */
package pits.form;

import java.util.ArrayList;
import java.util.List;

import javax.portlet.ActionRequest;

import org.apache.log4j.Logger;
import pits.util.Constants;

/**
 * This object uses to contain the value of JSP form.
 * 
 * @author ltd
 * 
 */
public class LoginForm {
	/**
	 * txtUserName property.
	 */
	private String txtUserName;
	/**
	 * txtPassword property.
	 */
	private String txtPassword;

	public LoginForm() {

	}

	public LoginForm(ActionRequest request) {
		if (request.getParameter("txtUserName") != null) {
			setUserName(request.getParameter("txtUserName"));
			// new pits.util.Logger().write("userName " +
			// request.getParameter("txtUserName"));
		}
		if (request.getParameter("txtPassword") != null) {
			setPassword(request.getParameter("txtPassword"));
			// new pits.util.Logger().write("txtPassword " +
			// request.getParameter("txtPassword"));
		}
	}

	/**
	 * @return the txtUserName
	 */
	public String getUserName() {
		return txtUserName;
	}

	/**
	 * @param txtUserName
	 *            the txtUserName to set
	 */
	public void setUserName(String txtUserName) {
		this.txtUserName = txtUserName;
	}

	/**
	 * @return the txtPassword
	 */
	public String getPassword() {
		return txtPassword;
	}

	/**
	 * @param txtPassword
	 *            the txtPassword to set
	 */
	public void setPassword(String txtPassword) {
		this.txtPassword = txtPassword;
	}

	/**
	 * Log property.
	 */
	private static Logger log = Logger.getLogger("LoginForm");

	/**
	 * Validate the input data.
	 * 
	 * @return
	 */
	public List<String> validate() {
		log.debug("validate.start");
		List<String> errorMess = new ArrayList<String>();
		// check whether the txtUserName is blank
		if (this.txtUserName.equals(Constants.BLANK_VALUE)) {
			errorMess.add("Please input the Username!");
			log.debug("validate.errorMess: Please input the Username!");
		}
		// check whether the txtPassword is blank
		if (this.txtPassword.equals(Constants.BLANK_VALUE)) {
			errorMess.add("Please input the Password!");
			log.debug("validate.errorMess: Please input the Password!");
		}
		log.debug("validate.end");
		// return error message list
		return errorMess;
	}

}
